﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestAND : MonoBehaviour {
	public static string PACKAGE = "com.seventh.blecore";

	// Use this for initialization
	void Start () {
		AndroidJavaObject ja = new AndroidJavaObject(PACKAGE+".UnityHelper");
		ja.Call("setHelper",new ListenerAdapter());
		byte[] data = ja.Call<byte[]>("getByteArray");
		
		for (int i = 0; i < data.Length; i++)
		{
			Debug.Log(data[i]);
		}
		ja.Call("callAndroid");

		ja.Call("callArray", new byte[] { 1, 2, 3, 4 });
		ja.Call("callArray", new int[] { 5, 6, 7, 8 });
		try
		{
			string[] sArray = ja.Call<string[]>("getStringArray");
			for (int i = 0; i < sArray.Length; i++)
			{
				Debug.Log(sArray[i]);
			}
		}catch (System.Exception e) {
			Debug.Log(e.StackTrace);
			Debug.Log(e.Message);
		}

		ja.Call("callArray", new string[] { "9", "10", "11", "12" });

	}

	// Update is called once per frame
	void Update () {
		
	}
}
public class ListenerAdapter :AndroidJavaProxy {
	public ListenerAdapter() : base(TestAND.PACKAGE + ".UnityCallback")
	{
		
	}
	void callInt(int value) {
		Debug.Log(value);
	}

	void callBoolean(bool value) { 
		Debug.Log(value);

	}

	void callFloat(float value) { 
		Debug.Log(value);

	}

	void callDouble(double value) { 
		Debug.Log(value);

	}

	void callByte(byte value) { 
		Debug.Log(value);

	}

	void callString(string value) { 
		Debug.Log(value);

	}

	void callByteArray(AndroidJavaObject value) {
		//Debug.Log("callByteArray 1");
		//Debug.Log("callByteArray "+value[0]);
		//Debug.Log(value.ToString());
		//Debug.Log("callByteArray 2");
		byte[] uByte = value.Get<byte[]>("array");
		for (int i = 0; i < uByte.Length; i++)
		{
			Debug.Log(uByte[i]);
		}

		//for (int i = 0; i < value.Length; i++)
  //      {
		//	Debug.Log(value[i]);
  //      }
	}

	void callJavaObject(AndroidJavaObject value) { 
		Debug.Log(value.ToString());
	}
}
